﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectManageSystemApi.Models;
using ProjectManageSystemApi.Services;
using ProjectManageSystemApi.Utilities;

namespace ProjectManageSystemApi.Controllers
{
    /// <summary>
    /// 图片上传接口
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.GroupName_v1)]
    public class UploadController : Controller
    {
        readonly IUploadServices _upload;
        public UploadController(IUploadServices upload) 
        {
            _upload = upload;
        }

        [HttpPost]
        [Route("UserCheckInfoUpload")]
        public ApiResult UserCheckInfoUpload(IFormFile file)
        {
            if (file == null || file.Length == 0) 
            {
                return ApiResultStatus.Fail(ApiResultCodes.PARAMS_FAILED);
            }
            return _upload.UserCheckInfoUpload(file, out string filePath)
                ? ApiResultStatus.Success(filePath)
                : ApiResultStatus.Fail(ApiResultCodes.SERVER_ERROR);
        }


        [HttpPost]
        [Route("CostInfoUpload")]
        public ApiResult CostInfoUpload(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return ApiResultStatus.Fail(ApiResultCodes.PARAMS_FAILED);
            }
            return _upload.CostInfoUpload(file, out string filePath)
                ? ApiResultStatus.Success(filePath)
                : ApiResultStatus.Fail(ApiResultCodes.SERVER_ERROR);
        }


        [HttpPost]
        [Route("ProjectItemInfoUpload")]
        public ApiResult ProjectItemInfoUpload(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return ApiResultStatus.Fail(ApiResultCodes.PARAMS_FAILED);
            }
            return _upload.ProjectItemInfoUpload(file, out string filePath)
                ? ApiResultStatus.Success(filePath)
                : ApiResultStatus.Fail(ApiResultCodes.SERVER_ERROR);
        }

        [HttpPost]
        [Route("ProjectBillInfoUpload")]
        public ApiResult ProjectBillInfoUpload(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return ApiResultStatus.Fail(ApiResultCodes.PARAMS_FAILED);
            }
            return _upload.ProjectBillInfoUpload(file, out string filePath)
                ? ApiResultStatus.Success(filePath)
                : ApiResultStatus.Fail(ApiResultCodes.SERVER_ERROR);
        }

        [HttpPost]
        [Route("AppUpload")]
        public ApiResult AppUpload(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return ApiResultStatus.Fail(ApiResultCodes.PARAMS_FAILED);
            }
            return _upload.AppUpload(file, out string filePath)
                ? ApiResultStatus.Success(filePath)
                : ApiResultStatus.Fail(ApiResultCodes.SERVER_ERROR);
        }
    }
}
